package ensib.sti.ssu.activities;

import java.io.File;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.AndroidCharacter;

public class PrendrePhotoActivity extends Activity {
	private final static int TAKE_PICTURE_CODE=0x908; 
	Intent data2 = new Intent();
	private String imageUri;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		  Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
		    File photo = new File(Environment.getExternalStorageDirectory(),  genFile("jpg"));
		    intent.putExtra(MediaStore.EXTRA_OUTPUT,
		            Uri.fromFile(photo));
		    imageUri = photo.getAbsolutePath();
		    startActivityForResult(intent, TAKE_PICTURE_CODE);
	}
	private String genFile(String string) {
		// TODO Auto-generated method stub
		return "capture_bloc_note"+( new Date().getTime())+"_"+getTaskId()+"."+string;
		 
	}
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
	    super.onActivityResult(requestCode, resultCode, data);
	    switch (requestCode) {
	    case TAKE_PICTURE_CODE:
	       if (resultCode == Activity.RESULT_OK) {
	        	
	        	data2.putExtra("imageurl", imageUri);
	        	 
	         
	            
	         } 
	    }
	    finish();
}
	@Override
	public void finish() {
		// TODO Auto-generated method stub
		setResult(RESULT_OK, data2);
		super.finish();
	}
}
